home *** CD-ROM | disk | FTP | other *** search
/ The Very Best of Atari Inside / The Very Best of Atari Inside 1.iso / mint / mntlib25 / mntlib25.zoo / _mulsi3.s < prev    next >
Text File  |  1992-12-12  |  1KB  |  50 lines

  1. | long integer multiplication routine
  2. |
  3. | written by Kai-Uwe Bloem (I5110401@dbstu1.bitnet).
  4. |
  5. |
  6. | Revision 1.1, kub 03-90
  7. | first version, replaces the appropriate routine from fixnum.s.
  8. | This one is longer, but normally faster because __umulsi3 is no longer
  9. | called for multiplication. Rather, the code is inlined here. See the
  10. | comments in _umulsi3.s
  11.  
  12.     .text
  13.     .even
  14.     .globl    __mulsi3, ___mulsi3, .lmul, .ulmul
  15.  
  16. .lmul:
  17. .ulmul:
  18. __mulsi3:
  19. ___mulsi3:
  20.     movel    d2,a0        | save registers
  21.     movel    d3,a1
  22.     movemw    sp@(4),d0-d3    | get the two longs. u = d0-d1, v = d2-d3
  23.     movew    d0,sp@-        | sign flag
  24.     bpl    0f        | is u negative ?
  25.     negw    d1        | yes, force it positive
  26.     negxw    d0
  27. 0:    tstw    d2        | is v negative ?
  28.     bpl    0f
  29.     negw    d3        | yes, force it positive ...
  30.     negxw    d2
  31.     notw    sp@        |  ... and modify flag word
  32. 0:
  33.     extl    d0        | u.h <> 0 ?
  34.     beq    1f
  35.     mulu    d3,d0        | r  = v.l * u.h
  36. 1:    tstw    d2        | v.h <> 0 ?
  37.     beq    2f
  38.     mulu    d1,d2        | r += v.h * u.l
  39.     addw    d2,d0
  40. 2:    swap    d0
  41.     clrw    d0
  42.     mulu    d3,d1        | r += v.l * u.l
  43.     addl    d1,d0
  44.     movel    a1,d3
  45.     movel    a0,d2
  46.     tstw    sp@+        | should the result be negated ?
  47.     bpl    3f        | no, just return
  48.     negl    d0        | else r = -r
  49. 3:    rts
  50.